package oracle.backingBeans;

import java.util.Map;

import javax.faces.context.FacesContext;

import oracle.adf.view.rich.component.rich.input.RichInputText;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

public class MBean
{
  private RichInputText motDePasse;
  private RichInputText nmotDePasse;
  private RichInputText cnMotDePasse;
  private BindingContainer bindings;

  public MBean()
  {
  }

  public void setMotDePasse(RichInputText motDePasse)
  {
    this.motDePasse = motDePasse;
  }

  public RichInputText getMotDePasse()
  {
    return motDePasse;
  }

  public void setNmotDePasse(RichInputText nmotDePasse)
  {
    this.nmotDePasse = nmotDePasse;
  }

  public RichInputText getNmotDePasse()
  {
    return nmotDePasse;
  }

  public void setCnMotDePasse(RichInputText cnMotDePasse)
  {
    this.cnMotDePasse = cnMotDePasse;
  }

  public RichInputText getCnMotDePasse()
  {
    return cnMotDePasse;
  }

  public BindingContainer getBindings()
  {
    if (this.bindings == null)
    {
      FacesContext fc = FacesContext.getCurrentInstance();
      this.bindings =
          (BindingContainer) fc.getApplication().evaluateExpressionGet(fc, "#{bindings}",
            BindingContainer.class);
    }
    return this.bindings;
  }

  public String commandButton_action()
  {
    System.out.println("Entree dans le bean");
    
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("memeMotDePasse");
    
    Map param = operationBinding.getParamsMap();
    
    param.put("motDePasse", this.motDePasse.getValue().toString());
    Boolean retour = (Boolean)operationBinding.execute();
    
    System.out.println(retour.booleanValue());
    
    //Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty())
    {
      return null;
    }
    return null;
  }

  public void setBindings(BindingContainer bindings)
  {
    this.bindings = bindings;
  }

  public String commandButton_action2()
  {
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("Commit");
    Object result = operationBinding.execute();
    System.out.println("works");
    if (!operationBinding.getErrors().isEmpty())
    {
      return null;
    }
    return null;
  }

  public String commandButton_action3()
  {
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("Delete");
    Object result = operationBinding.execute();
    
    //commandButton_action4();
    
    if (!operationBinding.getErrors().isEmpty())
    {
      return null;
    }
    return null;
  }

  public String commandButton_action4()
  {
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("Commit");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty())
    {
      return null;
    }
    return null;
  }
}
